package pinkblob.tools;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import pinkblob.entity.ProjectInformation;
import pinkblob.event.AProjectInformationHandler;
import pinkblob.event.ProjectInformationHandler;
import pinkblob.log.Log;

public class GarbageCollector {
	
	private ProjectInformationHandler pih;
	private SendMail mail;
	protected static Logger log = new Log()
	.getLogger(AProjectInformationHandler.class);
	
	public GarbageCollector() {	
		pih = new ProjectInformationHandler();
		
		List<ProjectInformation> projects = pih.getAllProjectInformation(false);
		log.info("Starting Garbage Collection");
		log.debug( projects.size() + "Projects");
		for (ProjectInformation pi : projects) {
			Date actualTime = new Date();
			log.info("Processing Project with ID " + pi.getProjectID() + "(DL: "+pi.getDeadline()+" - NOW: "+actualTime+")");
			if (       (pi.getStatus()%2 == 1 && pi.getDeadline().before(new Date()))
					|| (pi.isHighPriority()   && pi.getDeadline().before(new Date()))  ) {
				log.debug("Deadline exceeded");
				
				switch (pi.getStatus()) {
				case 1:
				case 3:
				case 5:
					SendMail.sendDelayNotification(pi.getProjectID());
					log.debug("calling SendMail.sendDelayNotification()");
					break;
				case 9:
					SendMail.triggerAdmonition(pi.getProjectID());
					log.debug("calling SendMail.triggerAdmonition()");
					break;
				}
				
			}
		}
	}

	public void ClearGarbage(){

	}
}
